package com.tf.xx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tf.xx.entity.EduTeacher;
import com.tf.xx.entity.vo.TeacherQuery;
import com.tf.xx.mapper.EduTeacherMapper;
import com.tf.xx.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.management.Query;

@Service
public class EduTeacherServiceImpl extends ServiceImpl<EduTeacherMapper, EduTeacher> implements EduTeacherService{

    @Autowired
    private EduTeacherMapper eduTeacherMapper;
    @Override
    public Page<EduTeacher> pageListTeacher(long page, long limit) {
        Page<EduTeacher> mypage = new Page<>(page,limit);
        Page<EduTeacher> eduTeacherPage = eduTeacherMapper.selectPage(mypage,null);
        return eduTeacherPage;
    }

    @Override
    public void pageQuery(Page<EduTeacher> pageParam, TeacherQuery teacherQuery) {
        QueryWrapper<EduTeacher> queryWrapper = new QueryWrapper<>();
        if (teacherQuery == null){
            eduTeacherMapper.selectPage(pageParam,queryWrapper);
        }
        if (teacherQuery.getName() != null && !"".equals(teacherQuery.getName())){
            queryWrapper.like("name",teacherQuery.getName());
        }
        if (teacherQuery.getLevel() != null && !"".equals(teacherQuery.getLevel())){
            queryWrapper.eq("level",teacherQuery.getLevel());
        }
        if (teacherQuery.getBegin() != null && !"".equals(teacherQuery.getBegin())){
            queryWrapper.ge("gmt_create",teacherQuery.getBegin());
        }
        if (teacherQuery.getEnd() != null && !"".equals(teacherQuery.getEnd())){
            queryWrapper.le("gmt_modified",teacherQuery.getEnd());
        }
        eduTeacherMapper.selectPage(pageParam,queryWrapper);

    }
}
